/**
 * Created by zhaohenry on 2017/7/18.
 */
import axios from 'axios'

axios.defaults.baseURL = 'http://nlelearn.com/wzz'
// axios.defaults.baseURL = 'http://10.140.72.11:8001/wzz'
// axios.defaults.baseURL = 'http://192.168.30.76:8234/wzz'
// axios.defaults.baseURL = 'http://192.168.14.17:8000/wzz'
axios.defaults.headers.common['Authorization'] = 'AUTH_TOKEN'
axios.defaults.headers.post['Content-Type'] = 'application/json'
// 上传地址
export const uploadURL = 'http://nlelearn.com:8234/wzz/upload/'
// ws地址
export const wsPath = 'ws://nlelearn.com:8234/ch/'
/**
 * 验证用户是否登录
*/
export const clientLogin = params => { return axios.post('/checkin/clientLogin/', params) }
export const clientLogout = params => { return axios.post('/checkin/clientLogout/', params) }
export const getClientUser = () => { return axios.get('/checkin/getClientUser/') }
/**
 * 创建实验
 */
// export const login = params => { return axios.post('/checkin/check_user/', params).then(res => res.status) }
/**
 * 设备类型
 */
export const DeviceType = (page) => { return axios.get('/DeviceType/?format=json&page=' + page) }

/**
 * 添加类型
 */
export const DeviceTypeAdd = params => { return axios.post('/DeviceType/', params) }

/**
 * 删除类型
 */
export const DeviceTypeDel = deviceId => { return axios.delete('/DeviceType/' + deviceId + '/') }

/**
 * 设备名称
 */
export const DeviceName = () => { return axios.get('/warehouse/showDevice/') }
export const DeviceStock = () => { return axios.get('/warehouse/showStock/') }

/**
 * 添加设备名称
 */
export const DeviceNameAdd = params => { return axios.post('/DeviceName/', params) }

/**
 * 删除设备名称
 */
export const DeviceNameDel = deviceId => { return axios.delete('/DeviceName/' + deviceId + '/') }

/**
 * 设备列表
 */
export const DeviceList = () => { return axios.get('/DeviceList/') }

/**
 * 添加设备
 */
export const DeviceListAdd = params => { return axios.post('/DeviceList/', params) }

/**
 * 更新设备
 */
export const DeviceListMod = deviceId => { return axios.put('/DeviceList/' + deviceId + '/').then(res => res.data) }

/**
 * 删除设备
 */
// export const DeviceListDel = deviceId => { return axios.delete('/DeviceList/' + deviceId + '/') }

/**
 * 获取当前及历史实验
 */
export const getCurrentTask = () => { return axios.get('/practice/currentTask/') }
export const getCurrentTaskM = () => { return axios.get('/practice/currentTaskM/') }
export const getHistoryTask = () => { return axios.get('/practice/historyTask/') }

/**
 * 用户管理
 */
export const getObjectList = (page) => { return axios.get('/myGroup/?format=json&page=' + page) }
export const getObjectListC = () => { return axios.get('/myGroup/?format=json&limit=1000') }
export const groupDel = groupId => { return axios.delete('/myGroup/' + groupId + '/') }
export const createGroup = params => { return axios.post('/myGroup/', params) }
export const patchGroup = (groupID, params) => { return axios.patch('/myGroup/' + groupID + '/', params) }

// export const getUserList = () => { return axios.get('/checkin/showUser/') }
export const getUserList = (page) => { return axios.get('/myUser/?format=json&page=' + page) }
export const getAllotUser = groupID => { return axios.get('/checkin/getAllotUser/' + groupID + '/') }
export const AllotUser = (groupID, params) => { return axios.put('/checkin/AllotUser/' + groupID + '/', params) }
export const userDel = userId => { return axios.delete('/myUser/' + userId + '/') }
export const createUser = params => { return axios.post('/checkin/createUser/', params) }
export const patchUser = (userID, params) => { return axios.patch('/checkin/patchUser/' + userID + '/', params) }
export const modifyPwd = params => { return axios.patch('/checkin/modifyPwd/', params) }

export const loginRecord = () => { return axios.get('/loginRecord/') }
export const getUserAndTaskId = () => { return axios.get('/checkin/SimulationCheck/') }

/**
 * 任务列表
 */
export const getTaskList = () => { return axios.get('/practice/getTaskList/') }
export const TaskListDel = taskId => { return axios.delete('/TaskList/' + taskId + '/') }
export const createTask = params => { return axios.post('/practice/createTask/', params).then(res => res.data) }  /* FIXME: 返回值 */
export const updateTask = (taskId, params) => { return axios.put('/practice/updateTask/' + taskId + '/', params) }
export const getTask = taskId => { return axios.get('/practice/getTask/' + taskId + '/') }
export const getStep = () => { return axios.get('/practice/getStep/') }
export const getPubTask = () => { return axios.get('/practice/getPubTaskMsg/') }
export const verify = taskId => { return axios.get('/mytest/' + taskId + '/') }
export const verifyr = taskId => { return axios.get('/mytestr/' + taskId + '/') }
export const getPublishList = (page) => { return axios.get('/PublishList/?format=json&page=' + page) }
export const getTaskData = taskId => { return axios.get('/getTaskData/' + taskId + '/') }
export const publishTask = params => { return axios.post('/publishTask/', params) }
export const publishDel = taskId => { return axios.delete('/PublishList/' + taskId + '/') }
export const getVerifyResult = taskId => { return axios.get('/getVerifyResult/' + taskId + '/') }
export const getVerifyResultR = taskId => { return axios.get('/getVerifyResultR/' + taskId + '/') }
export const updateStep = params => { return axios.patch('/practice/updateStep/', params) }

/**
 * 试卷相关
 */
export const createExam = params => { return axios.post('/exam/createExam/', params) }
export const getExamList = () => { return axios.get('/examList/') }
export const ExamListDel = examId => { return axios.delete('/examList/' + examId + '/') }
export const examDetail = examId => { return axios.get('/exam/showExam/' + examId + '/') }
export const publishExam = params => { return axios.post('/exam/examPublish/', params) }
export const getExamPublish = () => { return axios.get('/exam/getExamPublish/') }
export const stuGetExam = () => { return axios.get('/exam/stuGetExam/') }

/**
 * 刷卡登录
 */
export const loginCheck = params => { return axios.post('/checkin/loginCheck/', params) }
export const getGroupUser = () => { return axios.get('/checkin/getGroupUser/') }
export const monitorLogout = params => { return axios.post('/checkin/monitorLogout/', params) }

/**
 * 实验报告
 */
export const createReport = params => { return axios.post('/report/createReport/', params) }
export const listReport = (page) => { return axios.get('/report/listReport/?format=json&page=' + page) }
export const getReport = reportId => { return axios.get('/report/getReport/' + reportId + '/') }
export const uploadSimImage = params => { return axios.post('/report/simImage/', params) }
export const doRate = params => { return axios.post('/report/score/', params) }

/**
 * 举手
 */
export const handsUp = () => { return axios.post('/handsUp/') }

export const handsDown = () => { return axios.post('/handsDown/') }

export const getMonitorData = () => { return axios.get('/practice/getMonitorData/') }

/**
 * 工位相关
 */
export const pcList = (page) => { return axios.get('/pcList/?format=json&page=' + page) }
export const createPcList = params => { return axios.post('/pcList/', params) }
export const stationListC = () => { return axios.get('/StationList/') }
export const stationList = () => { return axios.get('/workstation/getStationList/') }
export const terminalList = (page) => { return axios.get('/terminalList/?format=json&page=' + page) }
export const createTerminalList = params => { return axios.post('/terminalList/', params) }
export const getUnPcList = () => { return axios.get('/workstation/getUnPcList/') }
export const getUnTermList = () => { return axios.get('/workstation/getUnTermList/') }
export const createStation = params => { return axios.post('/workstation/createStation/', params) }

/**
 * 消息
 */
export const message = slug => { return axios.get('/ch/' + slug + '/') }

/**
 * 出库
 */
export const stockOut = taskID => { return axios.get('/warehouse/stockOut/' + taskID + '/') }
export const stockStatus = () => { return axios.get('/warehouse/getStatus/') }

/**
 * 耗材管理
 */
export const getConsumableList = (page) => { return axios.get('/consumable/?format=json&page=' + page) }
// export const postConsumable = (cid, params) => { return axios.put('/consume/deleteConsum/' + cid + '/', params) }
export const deleteConsumable = cid => { return axios.delete('/consume/deleteConsum/' + cid + '/') }
export const createConsumable = params => { return axios.post('/consume/createConsum/', params) }
export const addConsumable = params => { return axios.post('/consume/createConsum/', params) }
export const adjustConsumable = params => { return axios.post('/consume/createConsum/', params) }
export const allotConsumable = params => { return axios.post('/consume/allotConsum/', params) }
export const getStationConsumable = () => { return axios.get('/consume/stationComsumable/') }
export const postStationConsumableUsage = (params) => { return axios.put('/consume/updateConsumStudent/', params) }
export const postStationConsumableAll = (params) => { return axios.put('/consume/updateConsumTeacher/', params) }

/**
 * 讨论区
 */
export const getAskList = (page) => { return axios.get('/discussionList/?page=' + page) }
export const getAskDetail = (askId) => { return axios.get('/discussionList/' + askId + '/') }
export const deleteAsk = (askId) => { return axios.delete('/discussionList/' + askId + '/') }
export const postAskPublish = (params) => { return axios.post('/discussionList/', params) }

export const getReplyAskList = (askID) => { return axios.get('/discussionReplyList/' + askID + '/') }
export const postReplyAskList = (askID, params) => { return axios.post('/discussionReplyList/' + askID + '/', params) }

/**
 * 格式化时间
 */
export const timeFormat = (time) => {
  let d = new Date(time)
  let month = (d.getMonth() + 1)
  let date = d.getDate()
  let hour = d.getHours()
  let mint = d.getMinutes()
  if ((d.getMonth() + 1) < 10) {
    month = '0' + (d.getMonth() + 1)
  }
  if (d.getDate() < 10) {
    date = '0' + d.getDate()
  }
  if (d.getHours() < 10) {
    hour = '0' + d.getHours()
  }
  if (d.getMinutes() < 10) {
    mint = '0' + d.getMinutes()
  }
  return d.getFullYear() + '-' + month + '-' + date + ' ' + hour + ':' + mint
}
